<?php

namespace Project\AuthentificationBundle\Session;

class SessionManager {

    private $mailuser;
    private $passuser;
    private $request;
    private $session;

    //Constructeur par default du SessionManager, prend en parametre l'objet request et la session
    public function __construct($session, $request = "") {
        $this->session = $session;
        if ($request != "") {
            $this->request = $request;
            $this->recupInfo();
        }
    }

    public function recupInfo() {
        $this->mailuser = $this->request->request->get('login');
        $this->passuser = $this->request->request->get('password');
    }

    public function getMailuser() {
        return $this->mailuser;
    }

    public function getPassuser() {
        return $this->passuser;
    }

    public function setSession($utilisateur) {
        $this->session->set('id_user', $utilisateur->getId());
        $this->session->set('nom', $utilisateur->getNom());
        $this->session->set('prenom', $utilisateur->getPrenom());
        $this->session->set('email', $utilisateur->getEmail());
        $this->session->set('role', $utilisateur->getRefRole()->getRole());
        
    }

    public function deconnexion() {
        $this->session->remove('id_user');
        $this->session->remove('nom');
        $this->session->remove('prenom');
        $this->session->remove('email');
        $this->session->remove('role');
    }

}

?>
